/**
 * Created by Administrator on 2017/5/25.
 */
"use strict";
//引入模块
const mongoose = require('mongoose');
const db = require('./db');

// Schema 结构
var BookshelfSchema = new mongoose.Schema({
    bsid      :{type:Number,index: true},//bsid
    uid     :{type:Number,index: true},//用户id
    bookshelf:[
        {
            sjid:{type : Number,index:true},
            sjname:{type:String},
            books:[
                {
                    readTime:{type:Number},
                    updateTime:{type:Number},
                    bid:{type:Number,index:true},
                    chapter:{type:Number,default:1,index:true},
                    chapterNmae:{type:String,default:"尚未阅读"}
                }
            ]
        }
    ]
});

BookshelfSchema.statics.findFn = function(obj,obj1, callback) {
    return this.model('Bookshelf').find(obj, callback).sort(obj1);
};
BookshelfSchema.statics.findFnLimit = function(obj,obj1,num1,callback) {
    return this.model('Bookshelf').find(obj).sort(obj1).limit(num1).exec(callback);
};
BookshelfSchema.statics.findSortOne = function(obj,obj1,callback) {
    return this.model('Bookshelf').findOne(obj).sort(obj1).exec(callback);
};
BookshelfSchema.statics.updateFn = function(obj,obj1,callback) {
    return this.model('Bookshelf').update(obj,obj1).exec(callback);
};
BookshelfSchema.statics.findConut = function(obj,callback) {
    return this.model('Bookshelf').find(obj).count().exec(callback);
};

var BookshelfModel = db.model('Bookshelf', BookshelfSchema);

module.exports=BookshelfModel;